#include "clog.h"

int logWrite(char* type,char *msg)
{
    char* filename;
    if(type == NULL)
    {
        filename = "../log/daily.log";
    }
    else
    {
        filename = "../log/error.log";
    }

    time_t rawtime;
    struct tm *timeinfo;

    time(&rawtime);
    timeinfo = localtime(&rawtime);

    // printf("Current local time and date: %s", asctime(timeinfo));
    
    char buf[1024] = { 0 };
    // printf("buf:%s\n",buf);
    sprintf(buf,"%d-%d-%d %d:%d:%d\t",1900 + timeinfo->tm_year,1+timeinfo->tm_mon,timeinfo->tm_mday,\
                timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec);
    strcat(buf,msg);
    FILE* fp = fopen(filename,"a+");
    fwrite(buf,strlen(buf),1,fp); fflush(fp);
    fclose(fp);
    return 1;
}